
<!--    <script>-->
<!--        checkRole('admin');-->
<!--    </script>-->

    <style>
        .saveConfBtn{
            margin-left: 120px;
            color:#fff;
            background-color:#40BEA6;
            border: 1px solid rgba(0,0,0,0.6);
            border-radius: 5px;
            padding: 5px 10px;
            font-size: 14px;
        }
        .saveConfBtn:hover{
            background-color:#009688;
            color:#fff;
            cursor: pointer;
        }

        .resetConfBtn{
            color:#fff;
            background-color:#FFA500;
            border: 1px solid rgba(0,0,0,0.6);
            border-radius: 5px;
            padding: 5px 10px;
            font-size: 14px;
            margin-left: 50px;
        }
        .resetConfBtn:hover{
            background-color:#FF8C00;
            color:#fff;
            cursor: pointer;
        }

        #userForm{
            width:90%;
            margin: 50px auto;
            padding: 10px 20px;
            /*margin-left: 80px;*/
        }
        .area{
            width: 520px;
            margin:0 auto;
            padding-bottom: 20px;
            font-size: 20px;
            height: 60px;
        }
        .area input,select{
            font-size: 14px;
            border: 1px solid rgba(0,0,0,0.4);
            border-radius: 5px;
            height: 25px;
            line-height: 25px;
        }
        input::-webkit-input-placeholder{
            font-size: 16px;
            line-height: 25px;
        }
        input{
            font-size: 14px;
            width: 110px;
        }
        .tip{
            font-size: 10px;
            color: #6495ED;
            margin-left: 90px;
        }
        .inputName{
            width: 200px;
            display: inline-block;
            text-align: right;
        }
        select{
            width: 220px;
        }
        #userHeader{
            margin: 0 auto;
            padding-top: 30px;
            text-align: center;
            font-weight: bold;
            color: rgba(255,50,12,0.7);
        }
        .unit{
            display: inline;
        }
    </style>


    <div class="padding-big">
        <div id="userHeader">
            <h1>系统配置信息</h1>
        </div>
        <div id="userForm">

<!--            <div class="area">-->
<!--                <div class="">-->
<!--                    <div class="inputName">-->
<!--                      <label for="notLoginTime">账户未登录期限:</label>-->
<!--                    </div>-->
<!--                    <input type="text" value=""-->
<!--                           id="notLoginTime" name="notLoginTime" width="40%" maxlength="3" placeholder="请输入天数"-->
<!--                           onblur="checkNotLoginTime()" onfocus="removeNotLoginTime()"/>-->
<!--                    <p class="unit" id="notLoginTimeTip">天</p>-->
<!--                </div>-->
<!--                <p class="tip">账号若一定时间段内未登录,自动转为休眠状态,默认为90天</p>-->
<!--            </div>-->

            <div class="area">
                <div class="">
                    <div class="inputName">
                        <label for="pwdValidTime">密码有效期限:</label>
                    </div>
                    <input type="text" value=""
                           id="pwdValidTime" name="pwdValidTime" width="40%" maxlength="2" placeholder="请输入天数"
                           onblur="checkPwdValidTime()" onfocus="removePwdValidTime()"/>
                    <p class="unit" id="pwdValidTimeTip">天</p>
                </div>
                <p class="tip">账号密码有效期为1-90天,默认为90天</p>
            </div>

            <div class="area">
                <div class="">
                    <div class="inputName">
                        <label for="accountValidTime">临时账号有效期:</label>
                    </div>
                    <input type="text" value=""
                           id="accountValidTime" name="accountValidTime" width="40%" maxlength="2" placeholder="请输入天数"
                           onblur="checkAccountValidTime()" onfocus="removeAccountValidTime()"/>
                    <p class="unit" id="accountValidTimeTip">天</p>
                </div>
                <p class="tip">临时账户有效期最长为90天,到期转为休眠状态，默认为90天</p>
            </div>

            <div class="area">
                <div class="">
                    <div class="inputName">
                        <label for="loginFailedNum">登录失败次数:</label>
                    </div>
                    <input type="text" value=""
                           id="loginFailedNum" name="loginFailedNum" width="40%" maxlength="2" placeholder="请输入次数"
                           onblur="checkLoginFailedNum()" onfocus="removeLoginFailedNum()"/>
                    <p class="unit" id="loginFailedNumTip">次</p>
                </div>
                <p class="tip">用户连续登录失败多次后,账户会暂时锁定,可选范围1-10,默认次数为5次</p>
            </div>

            <div class="area">
                <div class="">
                    <div class="inputName">
                        <label for="lockedTime">账户锁定时间:</label>
                    </div>
                    <input type="text" value=""
                           id="lockedTime" name="lockedTime" width="40%" maxlength="3" placeholder="请输入时间"
                           onblur="checkLockedTime()" onfocus="removeLockedTime()"/>
                    <p class="unit" id="lockedTimeTip">分钟</p>
                </div>
                <p class="tip">账户会暂时锁定至少20分钟,默认时间为20分钟</p>
            </div>

            <div class="area">
                <div class="">
                    <div class="inputName">
                        <label for="sessionMaxOverTime">会话超时时间:</label>
                    </div>
                   <input type="text" value=""
                           id="sessionMaxOverTime" name="sessionMaxOverTime" width="40%" maxlength="2" placeholder="请输入时间"
                           onblur="checkSessionMaxOverTime()" onfocus="removeSessionMaxOverTime()"/>
                    <p class="unit" id="sessionMaxOverTimeTip">分钟</p>
                </div>
                <p class="tip">系统会话超时时间:1-30分钟,默认为30分钟</p>
            </div>

            <div class="area">
                <div class="">
                    <div class="inputName">
                        <label for="concurrentMaxNum">用户最大并发量:</label>
                    </div>
                    <input type="text" value=""
                           id="concurrentMaxNum" name="concurrentMaxNum" width="40%" maxlength="5" placeholder="请输入并发量"
                           onblur="checkConcurrentMaxNum()" onfocus="removeConcurrentMaxNum()"/>
                    <p class="unit" id="concurrentMaxNumTip">人</p>
                </div>
                <p class="tip">设置系统用户最大并发会话限制,默认为50人</p>
            </div>

            <div class="area">
                <div class="">
                    <div class="inputName">
                        <label for="logMaxVolume">日志存储空间容量:</label>
                    </div>
                    <input type="text" value=""
                           id="logMaxVolume" name="logMaxVolume" width="40%" maxlength="10" placeholder="请输入容量"
                           onblur="checkLogMaxVolume()" onfocus="removeLogMaxVolume()"/>
                    <p class="unit" id="logMaxVolumeTip">GB</p>
                </div>
                <p class="tip">日志存储空间上限,至少1GB  默认:1GB</p>
            </div>

            <div class="area" style="margin-top: 20px;">
                <a href="javascript:void(0);"  class="resetConfBtn" id="resetSystemConfigBtn">
                    恢复系统默认值
                </a>
                <a href="javascript:void(0);"  class="saveConfBtn" id="saveSystemConfigBtn">
                    保存系统配置
                </a>
            </div>
        </div>
    </div>
    
    <script>
        getSystemConfig();

        var reg=/^\d{1,}$/;

        //验证或移除某个可以配置的系统配置框内的值，成对出现，就不一一注释


        /*暂不用*/function checkNotLoginTime() {
            removeNotLoginTime();
            var notLoginTime = $("#notLoginTime").val();
            //removeNotLoginTime()
            if(notLoginTime==""||notLoginTime==undefined){
                $("#notLoginTimeTip").after("<span class='notLoginTimeText' style='color:red;font-size: 12px'>&nbsp;账户未登录期限不能为空</span>");
                return false;
            } else if(!reg.test(notLoginTime)){
                $("#notLoginTimeTip").after("<span class='notLoginTimeText' style='color:red;font-size: 12px'>&nbsp;账户未登录期限格式不规范</span>");
                return false;
            }else{
                if(notLoginTime<=0){
                    $("#notLoginTimeTip").after("<span class='notLoginTimeText' style='color:red;font-size: 12px'>&nbsp;账户未登录期限不能为0天</span>");
                    return false;
                }else{
                    return true;
                }
            }
        }

        /*暂不用*/function removeNotLoginTime(){
            $(".notLoginTimeText").remove();
        }

        //检查密码有效期的输入合法性
        function checkPwdValidTime(){
            var pwdValidTime = $("#pwdValidTime").val();
            removePwdValidTime();
            if(pwdValidTime==""||pwdValidTime==undefined){
                $("#pwdValidTimeTip").after("<span class='pwdValidTimeText' style='color:red;font-size: 12px'>&nbsp;密码有效期限不能为空</span>");
                return false;
            }else if(!reg.test(pwdValidTime)||pwdValidTime<=0||pwdValidTime>90){
                $("#pwdValidTimeTip").after("<span class='pwdValidTimeText' style='color:red;font-size: 12px'>&nbsp;密码有效期限格式不规范</span>");
                return false;
            }else{
                    return true;

            }
        }

        function removePwdValidTime(){
            $(".pwdValidTimeText").remove();
        }

        function checkAccountValidTime(){
            removeAccountValidTime();
            var accountValidTime = $("#accountValidTime").val();
            if(accountValidTime==""||accountValidTime==undefined){
                $("#accountValidTimeTip").after("<span class='accountValidTimeText' style='color:red;font-size: 12px'>&nbsp;临时账号有效期不能为空</span>");
                return false;
            }else if(!reg.test(accountValidTime)||accountValidTime<=0||accountValidTime>90){
                $("#accountValidTimeTip").after("<span class='accountValidTimeText' style='color:red;font-size: 12px'>&nbsp;临时账号有效期不规范</span>");
                return false;
            }else{
                  return true;

            }
        }

        function removeAccountValidTime(){
            $(".accountValidTimeText").remove();
        }

        function checkLoginFailedNum(){
            removeLoginFailedNum();
            var loginFailedNum = $("#loginFailedNum").val();
            if(loginFailedNum==""||loginFailedNum==undefined){
                $("#loginFailedNumTip").after("<span class='loginFailedNumText' style='color:red;font-size: 12px'>&nbsp;登录失败次数不能为空</span>");
                return false;
            }else if(!reg.test(loginFailedNum)||loginFailedNum<=0||loginFailedNum>10){
                $("#loginFailedNumTip").after("<span class='loginFailedNumText' style='color:red;font-size: 12px'>&nbsp;登录失败次数不规范</span>");
                return false;
            }else{
                  return true;
            }
        }

        function removeLoginFailedNum(){
            $(".loginFailedNumText").remove();
        }

        function checkLockedTime(){
            var lockedTime = $("#lockedTime").val();
            removeLockedTime();
            if(lockedTime==""||lockedTime==undefined){
                $("#lockedTimeTip").after("<span class='lockedTimeText' style='color:red;font-size: 12px'>&nbsp;账户锁定时间不能为空</span>");
                return false;
            }else if(!reg.test(lockedTime)||lockedTime<20){
                $("#lockedTimeTip").after("<span class='lockedTimeText' style='color:red;font-size: 12px'>&nbsp;账户锁定时间不规范</span>");
                return false;
            }else{
                return true;
            }
        }

        function removeLockedTime(){
            $(".lockedTimeText").remove();
        }

        function checkSessionMaxOverTime(){
            var sessionMaxOverTime = $("#sessionMaxOverTime").val();
            removeSessionMaxOverTime();
            if(sessionMaxOverTime==""||sessionMaxOverTime==undefined){
                $("#sessionMaxOverTimeTip").after("<span class='sessionMaxOverTimeText' style='color:red;font-size: 12px'>&nbsp;会话超时时间不能为空</span>");
                return false;
            }else if(!reg.test(sessionMaxOverTime)||sessionMaxOverTime<=0||sessionMaxOverTime>30){
                $("#sessionMaxOverTimeTip").after("<span class='sessionMaxOverTimeText' style='color:red;font-size: 12px'>&nbsp;会话超时时间不规范</span>");
                return false;
            }else{
                return true;
            }
        }

        function removeSessionMaxOverTime(){
            $(".sessionMaxOverTimeText").remove();
        }

        function checkConcurrentMaxNum(){
            removeConcurrentMaxNum();
            var concurrentMaxNum = $("#concurrentMaxNum").val();
            if(concurrentMaxNum==""||concurrentMaxNum==undefined){
                $("#concurrentMaxNumTip").after("<span class='concurrentMaxNumText' style='color:red;font-size: 12px'>&nbsp;用户最大并发量:不能为空</span>");
                return false;
            }else if(!reg.test(concurrentMaxNum)||concurrentMaxNum<=0){
                $("#concurrentMaxNumTip").after("<span class='concurrentMaxNumText' style='color:red;font-size: 12px'>&nbsp;用户最大并发量:不规范</span>");
                return false;
            }else{
                return true;
            }
        }

        function removeConcurrentMaxNum(){
            $(".concurrentMaxNumText").remove();
        }

        function checkLogMaxVolume(){
            var logMaxVolume = $("#logMaxVolume").val();
            removeLogMaxVolume();
            if(logMaxVolume==""||logMaxVolume==undefined){
                $("#logMaxVolumeTip").after("<span class='logMaxVolumeText' style='color:red;font-size: 12px'>&nbsp;用户最大并发量不能为空</span>");
                return false;
            }else if(!reg.test(logMaxVolume)||logMaxVolume<1){
                $("#logMaxVolumeTip").after("<span class='logMaxVolumeText' style='color:red;font-size: 12px'>&nbsp;用户最大并发量不规范</span>");
                return false;
            }else{
                return true;
            }
        }

        function removeLogMaxVolume(){
            $(".logMaxVolumeText").remove();
        }

        /*提交*/
        $("#saveSystemConfigBtn").live("click",function () {
            isOnline("admin");
            $("#saveSystemConfigBtn").attr("disabled","disabled");
            var notLoginTime = $("#notLoginTime").val();
            var pwdValidTime = $("#pwdValidTime").val();
            var accountValidTime = $("#accountValidTime").val();
            var loginFailedNum = $("#loginFailedNum").val();
            var lockedTime = $("#lockedTime").val();
            var sessionMaxOverTime = $("#sessionMaxOverTime").val();
            var concurrentMaxNum = $("#concurrentMaxNum").val();
            var logMaxVolume = $("#logMaxVolume").val();


            if( checkPwdValidTime()
                &&checkAccountValidTime()
                &&checkLockedTime()
                &&checkLoginFailedNum()
                &&checkSessionMaxOverTime()
                &&checkLogMaxVolume()
                &&checkConcurrentMaxNum()){

                var systemconfig={
                    //notLoginTime:notLoginTime,
                    pwdValidTime:pwdValidTime,
                    accountValidTime:accountValidTime,
                    loginFailedNum:loginFailedNum,
                    lockedTime:lockedTime,
                    sessionMaxOverTime:sessionMaxOverTime,
                    concurrentMaxNum:concurrentMaxNum,
                    logMaxVolume:logMaxVolume
                };
                $.ajax({
                    url:HOST.concat("/updatesystemconfig?token=")+config.token+"&username="+getSessionStorage("username"),
                    data:JSON.stringify(systemconfig),
                    async:false,
                    contentType: "application/json",
                    type:'POST',
                    dataType:"JSON",
                    success:function (res) {
                       // console.log(res);
                        if(res.meta.state="success"){
                            alert(res.meta.message);
                            $("#saveSystemConfigBtn").removeAttr("disabled");
                            systemConfig();
                        }
                    },
                    error:function () {
                        alert("服务器异常");
                    }
                });


            }

        });

        /*重置*/
        $("#resetSystemConfigBtn").live("click",function(){
            isOnline("admin");
            $("#resetSystemConfigBtn").attr("disabled","disabled");
           // $("#notLoginTime").val("90");
            $("#pwdValidTime").val("90");
            $("#accountValidTime").val("90");
            $("#loginFailedNum").val("5");
            $("#lockedTime").val("20");
            $("#sessionMaxOverTime").val("30");
            $("#concurrentMaxNum").val("50");
            $("#logMaxVolume").val("1");

            if( checkPwdValidTime()
                &&checkAccountValidTime()
                &&checkLockedTime()
                &&checkLoginFailedNum()
                &&checkSessionMaxOverTime()
                &&checkLogMaxVolume()
                &&checkConcurrentMaxNum()){

                var systemconfig={
                    // notLoginTime: $("#notLoginTime").val(),
                    pwdValidTime:$("#pwdValidTime").val(),
                    accountValidTime:$("#accountValidTime").val(),
                    loginFailedNum: $("#loginFailedNum").val(),
                    lockedTime: $("#lockedTime").val(),
                    sessionMaxOverTime:$("#sessionMaxOverTime").val(),
                    concurrentMaxNum: $("#concurrentMaxNum").val(),
                    logMaxVolume: $("#logMaxVolume").val()
                };

                $.ajax({
                    url:HOST.concat("/updatesystemconfig?token=")+config.token+"&username="+getSessionStorage("username"),
                    data:JSON.stringify(systemconfig),
                    async:false,
                    contentType: "application/json",
                    type:'POST',
                    dataType:"JSON",
                    success:function (res) {
                        console.log(res);
                        if(res.meta.state="success"){
                            alert("系统参数恢复默认值成功");
                            $("#resetSystemConfigBtn").removeAttr("disabled");
                            systemConfig();
                        }

                    }

                });


            }

        });

        //获取系统配置
        function getSystemConfig() {
            isOnline("admin");
            $.ajax({
                url:HOST.concat("/getsystemconfig?token=")+config.token,
                type:"get",
                dataType:"json",
                success:function (res) {
                    //console.log(res);
                    if(res.meta.state=="success"){
                        var data=res.data;
                        // $("#notLoginTime").val(data.notLoginTime);
                        $("#pwdValidTime").val(data.pwdValidTime);
                        $("#accountValidTime").val(data.accountValidTime);
                        $("#concurrentMaxNum").val(data.concurrentMaxNum);
                        $("#lockedTime").val(data.lockedTime);
                        $("#logMaxVolume").val(data.logMaxVolume);
                        $("#sessionMaxOverTime").val(data.sessionMaxOverTime);
                        $("#loginFailedNum").val(data.loginFailedNum);
                    }
                }
                
                
            });

        }

    </script>





